package com.ruoyi.system.WebController;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.ByNews;
import com.ruoyi.system.service.IByNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 新闻Controller  api
 *
 * @author ruoyi
 * @date 2024-01-16
 */
@RestController
@RequestMapping("/byWeb/news")
public class WebNewsController extends BaseController {
    @Autowired
    private IByNewsService byNewsService;

    /**
     * 查询新闻列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ByNews byNews)
    {
        startPage();
        List<ByNews> list = byNewsService.selectByNewsList(byNews);
        return getDataTable(list);
    }

    /**
     * 获取新闻详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        //增加浏览次数
        ByNews byNews = byNewsService.selectByNewsById(id);
        Long hit = 0L;
        if(byNews.getHits()==null){

        }else{
            hit = byNews.getHits();
        }

        hit += 1;
        byNews.setHits(hit);
        byNewsService.updateByNews(byNews);
        return success(byNewsService.selectByNewsById(id));
    }

}
